<%@page import="entities.OrderEntity"%>
<%@page import="service.OrderService"%>
<%@page import="service.SellerService"%>
<%@page import="entities.SellerEntity"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
	+ request.getServerName() + ":" + request.getServerPort()
	+ path + "/";
	String sellerName = (String) session.getAttribute("sellerName");
	String password = (String) session.getAttribute("sellerpassword");
	SellerEntity seller = new SellerEntity();
	if (sellerName == null || password == null) {
		response.sendRedirect("_seller/index.jsp");
	} else {
		seller = SellerService.confirm(sellerName, password.trim());
	}

	//针对分页的
	//每页的记录数
	int pageSize = 20 ;
	//总订单数
	
	int count = 0;
	 count = SellerService.getOrderCount(request.getParameter("date"),seller.getId()+"");
	//总共的页数 
	int pageCount =count%pageSize==0?count/pageSize:(count/pageSize+1);
	
	String pageIndex  = request.getParameter("pageIndex");
					if(null==pageIndex){
						pageIndex = "1"; 
					}
					int pageNow = Integer.parseInt(pageIndex);
	String[] state  = {"确认已送餐","送餐"};
%>

<!DOCTYPE HTML>
<html>
<head>
<base href="<%=basePath%>">

<title>交易详情</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<script type="text/javascript" src="<%=basePath%>_seller/js/grid.js"></script>
<script type="text/javascript" src="<%=basePath%>js/jquery.min.js"></script>
<style type="text/css">
table#grid {
	width: 1000px;
	margin: auto;
	empty-cells: show;
	border-collapse: collapse;
	border-spacing: 0;
	empty-cells: show;
	margin: auto;
}

#grid td,#grid th {
	padding: 5px;
	border: #E3E3E3 1px solid;
	font-size: 13px;
	height: 16px;
	line-height: 16px;
}

#grid tr th {
	color: #ff0000;
	background-color: #ffffcc;
	font-size: 16px;
	font-weight: bold;
	padding: 8px 0px;
}

td.user {
	color: blue;
	font-weight: bold;
	font: 14px;
}

.orderDetail {
	color: #ff0000;
	font-weight: bold;
	font: 14px;
}

.page{
	width: 700px;
	text-align: center;
	margin-top: 8px;
    font-size: 14px;
    margin:10px auto;
}
.page span{
	padding: 0 6px;
	color: #ff74a9;
}
.page a{
	margin: 0 2px;
}

.page a:hover{
	color: #ff74a9;
}
</style>

</head>
<body>
	<jsp:include page="header.jsp"></jsp:include>

	<div style="display: none;" id="sellerId"><%=seller.getId() %></div>
	
	<%
		List<OrderEntity> orderList = new ArrayList();;
			orderList = SellerService.getOrderDesc2(request.getParameter("date"), seller.getId()+"",""+(pageNow - 1)*pageSize, pageSize+"");
	 %>

	
	<table id="grid" cellspacing="0" cellpadding="0" class="st">
		<thead>
			<tr class="st1" align="center">
				<th width="10%">下单时间</th>
				<th width="18%">订单号</th>
				<th width="25%">订餐信息</th>
				<th width="14%">收餐人信息</th>
				<th width="20%">送货地址</th>
			</tr>
		</thead>
		<tbody>
			<%
				for(int i=0 ;i<orderList.size();i++) {
			%>
			<tr>
				<td><%=orderList.get(i).getTime()%></td>
				<td><%=orderList.get(i).getNo()%></td>
				<td><span class="orderDetail"><%=orderList.get(i).getDetail()%></span></br> 小计：<span
					class="orderDetail"><%=OrderService.orderPrice(orderList.get(i).getNo(),
							seller.getId())%></span>元</td>
				<td class="user"><%=orderList.get(i).getToUser()%></td>
				<td><%=orderList.get(i).getToAddr()%></td>

			</tr>

			<%
				}
			%>
		</tbody>
	</table>
	<div class="page" align="center">
		          	共:<span><%=pageCount %></span>页(共<%=count %>条)；&nbsp;&nbsp;&nbsp;每页<span><%=pageSize %></span>条记录；&nbsp;&nbsp;当前为第<span><%=pageCount==0?0:pageNow%></span>页。<br/>
		          	<%if(pageNow>1){ %>
		            <a href="<%=basePath %>_seller/dealdetail.jsp?date=<%=request.getParameter("date") %>&pageIndex=<%=pageNow-1%>">上一页</a> 
		            <%}else{ %>
		            <a title="没有上一页啦">上一页</a> 
		            <%}
		              if(pageNow<pageCount){ %>
		            <a href="<%=basePath %>_seller/dealdetail.jsp?date=<%=request.getParameter("date") %>&pageIndex=<%=pageNow+1%>">下一页</a> 
		            <%}else{ %>
		            <a title="没有下一页啦">下一页</a> 
		            <%} %>
		            <a href="<%=basePath %>_seller/dealdetail.jsp?date=<%=request.getParameter("date") %>">首页</a>
		            <a href="<%=basePath %>_seller/dealdetail.jsp?date=<%=request.getParameter("date") %>&pageIndex=<%=pageCount==0?1:pageCount%>">末页</a>
			     </div>
	<script type="text/javascript">
		//grid("名称","奇数行背景","偶数行背景","鼠标经过背景","点击后背景");
		grid("grid", "#fff", "#F5F5F5", "#FFFFCC", "#f5f5f5");
		$(document).ready(function() {
			setInterval(function() {
				//$("#grid").html("");
			}, 5000);

			$(".changeState").click(function() {
				var sellerId = $("#sellerId").html();
				var orderNo = $(this).attr("id");
				var stateNow = parseInt($(this).attr("state"));
				var state = 4;
				alert(sellerId+"----"+orderNo);
				
				$.ajax({
					type : "POST",
					url : "servlet/OrderServlet",
					data : "action=updateState&userName=&sellerId=" + sellerId + "&orderNo="
							+ orderNo+"&state="+state,
					error : function(error) {
						var tip = $('a#LoginTip');
						tip.attr("class", "Error");
						tip.html("操作失败，请重试");
					},
					success : function(result) {
						if (result == "success") {
							//window.history.go(-1);
							window.location.reload(true);
							return;
						}
					}
				});
			});
		});
	</script>

</body>
</html>
